package cn.com.zpark.servlet_config;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @PackageName: cn.com.zpark.servlet_config
 * @ClassName: ServletConfigDemo01
 * @Description:
 * @author: RZS
 * @date: 2021/11/10  10:25
 */
public class ServletConfigDemo01 extends HttpServlet {

    private ServletConfig servletConfig;

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter writer = resp.getWriter();

        writer.write(servletConfig.getServletContext().toString());
        writer.write(servletConfig.getServletName());
        writer.write(servletConfig.getInitParameter("name"));
        writer.write(servletConfig.getInitParameter("local"));

        System.out.println(servletConfig.getInitParameter("name"));
        System.out.println(servletConfig.getInitParameter("local"));
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        this.servletConfig = config;
    }
}
